/* See LICENSE for copyright and terms of use */

import org.as2lib.test.unit.TestCase;

import org.evtmng.timeline.Timeline;
import org.evtmng.tween.Tween;
import org.evtmng.util.List;

/**
 * @author Tay Ray Chuan
 */

class org.evtmng.test.unit.TimelineTest extends TestCase {
	private var m_tl:Timeline;

	public function setUp():Void {
		m_tl = new Timeline();
	}

	public function testLocks():Void {
		var end:Number = 100;
		var f1:Tween = new Tween(10, end);
		var f2:Tween = new Tween(20, end);
		var f3:Tween = new Tween(30, end);
		var len:Number, LENGTH:Number;

		m_tl.addTween(f1);
		m_tl.addTween(f2);

		assertNotNull(m_tl.tweensForEnd(end));
		assertTrue(m_tl.tweensForEnd(end) instanceof List);

		LENGTH = m_tl.tweensForEnd(end).length();

		assertEquals(LENGTH, 2);

		m_tl.lock();

		// trigger error message
		m_tl.addTween(f3);

		len = m_tl.tweensForEnd(end).length();

		assertEquals(LENGTH, len);

		m_tl.unlock();

		// all ok
		m_tl.addTween(f3);
		m_tl.removeTween(f1);
		m_tl.removeTween(f2);

		len = m_tl.tweensForEnd(end).length();

		assertEquals(len, 1);
	}

	public function tearDown():Void {
		m_tl.unlock();
		delete m_tl;
	}
}